home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / QuickTime / JPEG Sample / Source / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-05  |  3.9 KB  |  174 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************
  2. #
  3. #        init.c
  4. #
  5. #        basic initialization code.
  6. #
  7. #        Author(s):     Michael Marinkovich & Guillermo Ortiz
  8. #                    marink@apple.com
  9. #
  10. #        Modification History: 
  11. #
  12. #            4/3/96        MWM     Initial coding                     
  13. #
  14. #        Copyright © 1992-96 Apple Computer, Inc., All Rights Reserved
  15. #
  16. #
  17. #        You may incorporate this sample code into your applications without
  18. #        restriction, though the sample code has been provided "AS IS" and the
  19. #        responsibility for its operation is 100% yours.  However, what you are
  20. #        not permitted to do is to redistribute the source as "DSC Sample Code"
  21. #        after having made changes. If you're going to re-distribute the source,
  22. #        we require that you make it clear in the source that the code was
  23. #        descended from Apple Sample Code, but that you've made changes.
  24. #
  25. *************************************************************************************/
  26.  
  27. #include <AppleEvents.h>
  28. #include <Displays.h>
  29. #include <Events.h>
  30. #include <Fonts.h>
  31. #include <Gestalt.h>
  32. #include <Menus.h>
  33. #include <OSUtils.h>
  34.  
  35. #include "App.h"
  36. #include "Proto.h"
  37.  
  38.  
  39. //----------------------------------------------------------------------
  40. //
  41. //    Globals - 
  42. //
  43. //----------------------------------------------------------------------
  44.  
  45. extern Boolean             gHasDMTwo;
  46. extern Boolean             gHasDrag;
  47. extern Boolean            gInBackground;
  48. extern short            gWindCount;
  49.  
  50.  
  51. //----------------------------------------------------------------------
  52. //
  53. //    Initialize - the main entry point for the initialization
  54. //
  55. //
  56. //----------------------------------------------------------------------
  57.  
  58. OSErr Initialize(void)
  59. {
  60.     OSErr        err = noErr;
  61.     
  62.     
  63.     ToolBoxInit();
  64.     CheckEnvironment();
  65.     err = InitApp();
  66.     
  67.     return err;
  68. }
  69.  
  70.  
  71. //----------------------------------------------------------------------
  72. //
  73. //    ToolBoxInit - initialization all the needed managers
  74. //
  75. //
  76. //----------------------------------------------------------------------
  77.  
  78. void ToolBoxInit(void)
  79. {
  80.  
  81.     InitGraf(&qd.thePort);
  82.     InitFonts();
  83.     InitWindows();
  84.     InitMenus();
  85.     TEInit();
  86.     InitDialogs(nil);
  87.     InitCursor();
  88.         
  89.     FlushEvents(everyEvent, 0);
  90.  
  91. }
  92.  
  93.  
  94. //----------------------------------------------------------------------
  95. //
  96. //    CheckEnvironment - make sure we can run with current sys and managers.
  97. //                       Also initialize globals - have drag & drop
  98. //                      
  99. //----------------------------------------------------------------------
  100.  
  101. void CheckEnvironment(void)
  102. {
  103.     OSErr            err;
  104.     long            response;
  105.  
  106.     // require QuickTime 1.5 or later
  107.     err = Gestalt(gestaltQuickTime, &response);
  108.     if (noErr != err || ((response >> 16) & 0xFFFF) < 0x0150)
  109.          HandleAlert(kNeedsQuickTime);
  110.  
  111.     // check to see if the Display Manager is present. If it is 
  112.     // then we have a PowerMac or System 7.5.
  113.     err = Gestalt(gestaltDisplayMgrAttr, &response);
  114.     
  115.     if (err != noErr || ((response & (1 << gestaltDisplayMgrPresent)) == 0))
  116.          HandleAlert(kNeedsDisplayManager);
  117.     
  118.     // check for Display Manager 2.0
  119.     else 
  120.     {
  121.         Gestalt(gestaltDisplayMgrVers, (long*)&response);
  122.         gHasDMTwo = (response >= 0x00020000);
  123.     }
  124.  
  125. }
  126.  
  127.  
  128. //----------------------------------------------------------------------
  129. //
  130. //    InitApp - initialization all the application specific stuff
  131. //
  132. //
  133. //----------------------------------------------------------------------
  134.  
  135. OSErr InitApp(void)
  136. {
  137.     OSErr                err;
  138.  
  139.     // init AppleEvents
  140.     err = AEInit();
  141.     MenuSetup();
  142.  
  143.     // Install Display Manager AppleEvent Notification
  144.     err = InstallAEDMNotification();
  145.  
  146.     // init any globals
  147.     gWindCount = 1;
  148.  
  149.     return err;                    
  150. }
  151.  
  152.  
  153. //----------------------------------------------------------------------
  154. //
  155. //    MenuSetup - 
  156. //
  157. //
  158. //----------------------------------------------------------------------
  159.  
  160. void MenuSetup(void)
  161. {
  162.     Handle            menu;
  163.         
  164.         
  165.     menu = GetNewMBar(rMBarID);        //    get our menus from resource
  166.     SetMenuBar(menu);
  167.     DisposeHandle(menu);
  168.     AddResMenu(GetMHandle(mApple ), 'DRVR');        //    add apple menu items
  169.  
  170.     DrawMenuBar();
  171.  
  172.         
  173. }
  174.